package rlpw.util;

import java.util.*;

public class RotationSet<T> {
	private List<T> entries = new ArrayList<T>();
	private int count;
	private int last;
	
	public RotationSet() {
		this.setCount(0);
	}
	
	public RotationSet(int count) {
		this.setCount(count);
	}
	
	public boolean add(T item) {
		if (entries.size() < getCount()) {
			entries.add(item);
			return true;
		} else {
			return false;
		}
	}
	
	public void clear() {
		entries.clear();
	}
	
	public boolean isFull() {
		return (getCount() == entries.size());
	}
	
	public T get(int index) {
		last = index % getCount();
		return entries.get(last);
	}
	
	public T next() {
		return get(++last);
	}
	
	public int indexOf(T item) {
		return entries.indexOf(item);
	}
	
	@SuppressWarnings("unchecked")
	public T[] toArray() {
		return (T[]) entries.toArray(); 
	}

	public void setCount(int count) {
		this.count = count;
	}

	public int getCount() {
		return count;
	}

}
